package com.hyperboost.backend.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hyperboost.common.annotation.Log;
import com.hyperboost.common.core.controller.BaseController;
import com.hyperboost.common.core.domain.AjaxResult;
import com.hyperboost.common.enums.BusinessType;
import com.hyperboost.backend.domain.OpportunityComment;
import com.hyperboost.backend.service.IOpportunityCommentService;
import com.hyperboost.common.utils.poi.ExcelUtil;
import com.hyperboost.common.core.page.TableDataInfo;

/**
 * 机会评论Controller
 * 
 * @author LXY
 * @date 2025-04-11
 */
@RestController
@RequestMapping("/backend/comment")
public class OpportunityCommentController extends BaseController
{
    @Autowired
    private IOpportunityCommentService opportunityCommentService;

    /**
     * 查询机会评论列表
     */
    @PreAuthorize("@ss.hasPermi('backend:comment:list')")
    @GetMapping("/list")
    public TableDataInfo list(OpportunityComment opportunityComment)
    {
        startPage();
        List<OpportunityComment> list = opportunityCommentService.selectOpportunityCommentList(opportunityComment);
        return getDataTable(list);
    }

    /**
     * 导出机会评论列表
     */
    @PreAuthorize("@ss.hasPermi('backend:comment:export')")
    @Log(title = "机会评论", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OpportunityComment opportunityComment)
    {
        List<OpportunityComment> list = opportunityCommentService.selectOpportunityCommentList(opportunityComment);
        ExcelUtil<OpportunityComment> util = new ExcelUtil<OpportunityComment>(OpportunityComment.class);
        util.exportExcel(response, list, "机会评论数据");
    }

    /**
     * 获取机会评论详细信息
     */
    @PreAuthorize("@ss.hasPermi('backend:comment:query')")
    @GetMapping(value = "/{commentId}")
    public AjaxResult getInfo(@PathVariable("commentId") Long commentId)
    {
        return success(opportunityCommentService.selectOpportunityCommentByCommentId(commentId));
    }

    /**
     * 新增机会评论
     */
    @PreAuthorize("@ss.hasPermi('backend:comment:add')")
    @Log(title = "机会评论", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OpportunityComment opportunityComment)
    {
        return toAjax(opportunityCommentService.insertOpportunityComment(opportunityComment));
    }

    /**
     * 修改机会评论
     */
    @PreAuthorize("@ss.hasPermi('backend:comment:edit')")
    @Log(title = "机会评论", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OpportunityComment opportunityComment)
    {
        return toAjax(opportunityCommentService.updateOpportunityComment(opportunityComment));
    }

    /**
     * 删除机会评论
     */
    @PreAuthorize("@ss.hasPermi('backend:comment:remove')")
    @Log(title = "机会评论", businessType = BusinessType.DELETE)
	@DeleteMapping("/{commentIds}")
    public AjaxResult remove(@PathVariable Long[] commentIds)
    {
        return toAjax(opportunityCommentService.deleteOpportunityCommentByCommentIds(commentIds));
    }
}
